package com.laterem.rtc.service.impl;

import com.laterem.rtc.service.RtcService;
import io.agora.media.RtcTokenBuilder2;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @creator: alan wu
 * @dateTime: 2023/5/18 14:14
 * @desc:
 */
@Service
public class RtcServiceImpl implements RtcService {

    static String appId = "5ddd5729ce164045a82f43e20f6e1d31";
    static String appCertificate = "b434bc2b6dc34b3b9afa430cd19296f9";
    static String channelName = "直播答题";
    static String account = "2082341273";
    static int uid = 2082341273;
    static int tokenExpirationInSeconds = 3600;
    static int privilegeExpirationInSeconds = 3600;

    @Override
    public Map<String, Object> token(){

        RtcTokenBuilder2 token = new RtcTokenBuilder2();
        String result = token.buildTokenWithUid(appId, appCertificate, channelName, uid, RtcTokenBuilder2.Role.ROLE_SUBSCRIBER, tokenExpirationInSeconds, privilegeExpirationInSeconds);
        System.out.println("Token with uid: " + result);

        result = token.buildTokenWithUserAccount(appId, appCertificate, channelName, account, RtcTokenBuilder2.Role.ROLE_SUBSCRIBER, tokenExpirationInSeconds, privilegeExpirationInSeconds);
        System.out.println("Token with account: " + result);

        result = token.buildTokenWithUid(appId, appCertificate, channelName, uid, privilegeExpirationInSeconds, privilegeExpirationInSeconds, privilegeExpirationInSeconds, privilegeExpirationInSeconds, privilegeExpirationInSeconds);
        System.out.println("Token with uid and privilege: " + result);

        result = token.buildTokenWithUserAccount(appId, appCertificate, channelName, account, privilegeExpirationInSeconds, privilegeExpirationInSeconds, privilegeExpirationInSeconds, privilegeExpirationInSeconds, privilegeExpirationInSeconds);
        System.out.println("Token with account and privilege: " + result);
        Map<String, Object> data = new HashMap<>();
        data.put("channelName", channelName);
        data.put("account", account);
        data.put("token", result);
        return data;
    }
}
